package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.QualityAssessment;
import com.pureut.system.domain.ReviewInformation;
import com.pureut.system.domain.vo.QualityAssessmentVo;
import com.pureut.system.service.IQualityAssessmentService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-08 16:15:48
 * @Desc: 质量考核单管理表Controller
 */
@RestController
@RequestMapping("/system/qualityAssessment")
public class QualityAssessmentController extends BaseController {

    /**
     * 质量考核单管理表Service
     */
    @Resource
    private IQualityAssessmentService qualityAssessmentService;

    /**
     * 查询质量考核单管理表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("qualityAssessment-list")
    @GetMapping("/list")
    public TableDataInfo list( QualityAssessmentVo qualityAssessmentVo) {
        startPage();
        LambdaQueryWrapper<QualityAssessment> resultQuery = new LambdaQueryWrapper<QualityAssessment>();
        if(ObjectUtil.isNotNull(qualityAssessmentVo.getFormNumber())){
            resultQuery.like(QualityAssessment::getFormNumber, qualityAssessmentVo.getFormNumber());
        }
        if(ObjectUtil.isNotNull(qualityAssessmentVo.getQualityInfo())){
            resultQuery.like(QualityAssessment::getQualityInfo, qualityAssessmentVo.getQualityInfo());
        }
        if(ObjectUtil.isNotNull(qualityAssessmentVo.getStartTime())&&ObjectUtil.isNotNull(qualityAssessmentVo.getEndTime())){
            resultQuery.between(QualityAssessment::getCreateTime, qualityAssessmentVo.getStartTime(),qualityAssessmentVo.getEndTime());
        }
        return getDataTable(qualityAssessmentService.list(resultQuery));
    }


    /**
     * 获取质量考核单管理表详细信息
     * @param: id 质量考核单管理表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("qualityAssessment-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(qualityAssessmentService.getById(id));
    }

    /**
     * 新增质量考核单管理表
     * @param: qualityAssessment 质量考核单管理表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("qualityAssessment-add")
    @PostMapping
    public AjaxResult add( @RequestBody QualityAssessmentVo qualityAssessmentVo) {
        return toAjax(qualityAssessmentService.save(qualityAssessmentVo));
    }

    /**
     * 修改质量考核单管理表
     * @param: qualityAssessment 质量考核单管理表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("qualityAssessment-edit")
    @PutMapping
    public AjaxResult edit(@RequestBody QualityAssessmentVo qualityAssessmentVo) {
        return toAjax(qualityAssessmentService.updateById(qualityAssessmentVo));
    }

    /**
     * 删除质量考核单管理表
     * @param: id 质量考核单管理表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("qualityAssessment-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qualityAssessmentService.removeByIds(Arrays.asList(ids)));
    }
}
